package siga.visao_financeiro;

import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import siga.banco.conexao;
import siga.visao.index;
import siga.visao.verErros;

/**
 *
 * @author rafaelfrasson
 */
public class movCaixaEditarVer extends javax.swing.JDialog {
    public static boolean ConfirmaEditar;
    public static boolean isConfirmaEditar() {
        return ConfirmaEditar;
    }
    public static void setConfirmaEditar(boolean ConfirmaEditar) {
        movCaixaEditarVer.ConfirmaEditar = ConfirmaEditar;
    }

    public String cod_lanc;
    public List cod_pessoa = new ArrayList();
    List PlanoPag = new ArrayList();
    List CentroCusto = new ArrayList();
    List PlanoContas = new ArrayList();
    public movCaixaEditarVer(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jpMCEVPrincipal = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jtfCodigo = new javax.swing.JTextField();
        jtfPessoa = new javax.swing.JTextField();
        jtfDtVenc = new javax.swing.JFormattedTextField();
        jtfPlanoPag = new javax.swing.JTextField();
        jtfCentroCusto = new javax.swing.JTextField();
        jtfPlanoContas = new javax.swing.JTextField();
        jtfValor = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtfHistorico = new javax.swing.JTextPane();
        jbPlanoPag = new javax.swing.JButton();
        jbPlanoContas = new javax.swing.JButton();
        jbCentroCusto = new javax.swing.JButton();
        jbPessoa = new javax.swing.JButton();
        jbCancelar = new javax.swing.JButton();
        jbSalvar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Editar Boleto");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });

        jpMCEVPrincipal.setFont(new java.awt.Font("SansSerif", 0, 11));
        jpMCEVPrincipal.setName("jpMCEVPrincipal"); // NOI18N
        jpMCEVPrincipal.setNextFocusableComponent(jtfDtVenc);

        jLabel1.setFont(new java.awt.Font("SansSerif", 0, 11));
        jLabel1.setText("Código:");
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setFont(new java.awt.Font("SansSerif", 0, 11));
        jLabel2.setText("Pessoa:");
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setFont(new java.awt.Font("SansSerif", 0, 11));
        jLabel3.setText("Histórico:");
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setFont(new java.awt.Font("SansSerif", 0, 11));
        jLabel4.setText("Data de Vencimento:");
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setFont(new java.awt.Font("SansSerif", 0, 11));
        jLabel5.setText("Valor Bruto:");
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setFont(new java.awt.Font("SansSerif", 0, 11));
        jLabel6.setText("Plano de Pagamento:");
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel7.setFont(new java.awt.Font("SansSerif", 0, 11));
        jLabel7.setText("Centro de Custo:");
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel8.setFont(new java.awt.Font("SansSerif", 0, 11));
        jLabel8.setText("Plano de Contas:");
        jLabel8.setName("jLabel8"); // NOI18N

        jtfCodigo.setEditable(false);
        jtfCodigo.setFont(new java.awt.Font("SansSerif", 0, 11));
        jtfCodigo.setName("jtfCodigo"); // NOI18N

        jtfPessoa.setEditable(false);
        jtfPessoa.setFont(new java.awt.Font("SansSerif", 0, 11));
        jtfPessoa.setName("jtfPessoa"); // NOI18N

        try {
            jtfDtVenc.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jtfDtVenc.setName("jtfDtVenc"); // NOI18N

        jtfPlanoPag.setEditable(false);
        jtfPlanoPag.setFont(new java.awt.Font("SansSerif", 0, 11));
        jtfPlanoPag.setName("jtfPlanoPag"); // NOI18N

        jtfCentroCusto.setEditable(false);
        jtfCentroCusto.setFont(new java.awt.Font("SansSerif", 0, 11));
        jtfCentroCusto.setName("jtfCentroCusto"); // NOI18N

        jtfPlanoContas.setEditable(false);
        jtfPlanoContas.setFont(new java.awt.Font("SansSerif", 0, 11));
        jtfPlanoContas.setName("jtfPlanoContas"); // NOI18N

        jtfValor.setFont(new java.awt.Font("SansSerif", 0, 11));
        jtfValor.setName("jtfValor"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jtfHistorico.setFont(new java.awt.Font("SansSerif", 0, 11));
        jtfHistorico.setName("jtfHistorico"); // NOI18N
        jScrollPane1.setViewportView(jtfHistorico);

        jbPlanoPag.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/busca_16x16.png"))); // NOI18N
        jbPlanoPag.setEnabled(false);
        jbPlanoPag.setName("jbPlanoPag"); // NOI18N

        jbPlanoContas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/busca_16x16.png"))); // NOI18N
        jbPlanoContas.setEnabled(false);
        jbPlanoContas.setName("jbPlanoContas"); // NOI18N

        jbCentroCusto.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/busca_16x16.png"))); // NOI18N
        jbCentroCusto.setEnabled(false);
        jbCentroCusto.setName("jbCentroCusto"); // NOI18N

        jbPessoa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/busca_16x16.png"))); // NOI18N
        jbPessoa.setEnabled(false);
        jbPessoa.setName("jbPessoa"); // NOI18N

        jbCancelar.setText("Cancelar");
        jbCancelar.setToolTipText("Cancela a Ação");
        jbCancelar.setName("jbCancelar"); // NOI18N
        jbCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCancelarActionPerformed(evt);
            }
        });

        jbSalvar.setText("Confirmar");
        jbSalvar.setToolTipText("Confirma a Ação");
        jbSalvar.setName("jbSalvar"); // NOI18N
        jbSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbSalvarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpMCEVPrincipalLayout = new javax.swing.GroupLayout(jpMCEVPrincipal);
        jpMCEVPrincipal.setLayout(jpMCEVPrincipalLayout);
        jpMCEVPrincipalLayout.setHorizontalGroup(
            jpMCEVPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpMCEVPrincipalLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpMCEVPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpMCEVPrincipalLayout.createSequentialGroup()
                        .addGroup(jpMCEVPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jtfCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jpMCEVPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jtfDtVenc, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addComponent(jtfPessoa, javax.swing.GroupLayout.DEFAULT_SIZE, 314, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbPessoa, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(22, 22, 22))
                    .addGroup(jpMCEVPrincipalLayout.createSequentialGroup()
                        .addGroup(jpMCEVPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jtfPlanoPag, javax.swing.GroupLayout.DEFAULT_SIZE, 314, Short.MAX_VALUE)
                            .addComponent(jLabel8)
                            .addComponent(jtfPlanoContas, javax.swing.GroupLayout.DEFAULT_SIZE, 314, Short.MAX_VALUE)
                            .addComponent(jtfCentroCusto, javax.swing.GroupLayout.DEFAULT_SIZE, 314, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jpMCEVPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jbPlanoContas, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jbPlanoPag, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jbCentroCusto, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(22, 22, 22))
                    .addComponent(jLabel7)
                    .addGroup(jpMCEVPrincipalLayout.createSequentialGroup()
                        .addGroup(jpMCEVPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jpMCEVPrincipalLayout.createSequentialGroup()
                                .addGroup(jpMCEVPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel5)
                                    .addComponent(jtfValor, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(33, 33, 33))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 347, Short.MAX_VALUE)
                            .addComponent(jLabel3)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpMCEVPrincipalLayout.createSequentialGroup()
                                .addComponent(jbSalvar)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jbCancelar)))
                        .addGap(22, 22, 22))))
        );
        jpMCEVPrincipalLayout.setVerticalGroup(
            jpMCEVPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpMCEVPrincipalLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpMCEVPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jpMCEVPrincipalLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtfCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtfPessoa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jbPessoa))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpMCEVPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jpMCEVPrincipalLayout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtfDtVenc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtfPlanoPag, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jbPlanoPag))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpMCEVPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jpMCEVPrincipalLayout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addGap(3, 3, 3)
                        .addComponent(jtfPlanoContas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jbPlanoContas))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpMCEVPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jpMCEVPrincipalLayout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addGap(3, 3, 3)
                        .addComponent(jtfCentroCusto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jbCentroCusto))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtfValor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
                .addGroup(jpMCEVPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbCancelar)
                    .addComponent(jbSalvar))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpMCEVPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpMCEVPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCancelarActionPerformed
        dispose();
    }//GEN-LAST:event_jbCancelarActionPerformed

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
        try {
            conexao.Query("select fr.*,fc.descricao as desc_conta, fp.descricao as desc_custo, fpp.descricao as desc_pagamento from fin_contas_mov_r fr " +
                    "left join fin_plano_contas fc on fc.codigo=fr.cod_plano_contas and fc.cod_emp=fr.cod_emp " +
                    "left join fin_plano_centro fp on fr.cod_centro_custos = fp.codigo and fr.cod_emp=fp.cod_emp " +
                    "left join fin_plano_pagamento fpp on fpp.codigo=fr.cod_plano_pagamento and fpp.cod_emp=fr.cod_emp " +
                    "where fr.cod_emp="+index.cod_emp+" and fr.codigo="+cod_lanc);
            conexao.rs.next();
            jtfCodigo.setText(conexao.rs.getString("codigo"));
            jtfPessoa.setText(cod_pessoa.get(1).toString());
            jtfDtVenc.setText(new SimpleDateFormat("dd/MM/yyyy").format(conexao.rs.getDate("dt_vencimento")));
            if(conexao.rs.getString("descricao") != null){
                jtfHistorico.setText(conexao.rs.getString("descricao"));
            }
            CentroCusto.add(0,conexao.rs.getString("cod_centro_custos"));
            CentroCusto.add(1,conexao.rs.getString("desc_custo"));
            jtfCentroCusto.setText(conexao.rs.getString("desc_custo"));
            PlanoContas.add(0, conexao.rs.getString("cod_plano_contas"));
            PlanoContas.add(1, conexao.rs.getString("desc_conta"));
            jtfPlanoContas.setText(conexao.rs.getString("desc_conta"));
            PlanoPag.add(0,conexao.rs.getString("cod_plano_pagamento"));
            PlanoPag.add(1,conexao.rs.getString("desc_pagamento"));
            jtfPlanoPag.setText(conexao.rs.getString("desc_pagamento"));
            jtfValor.setText(index.ftbr.format(conexao.rs.getDouble("valor_bruto")));
        } catch (SQLException ex) {
            verErros.setErro(ex.getMessage());
        }
    }//GEN-LAST:event_formWindowActivated

    private void jbSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbSalvarActionPerformed
        try {
            String data = new SimpleDateFormat("yyyy-MM-dd").format(new SimpleDateFormat("dd/MM/yyyy").parse(jtfDtVenc.getText()));
            double valor = index.ftes.parse(jtfValor.getText()).doubleValue();
            conexao.stm.executeUpdate("update fin_contas_mov_r set dt_vencimento=\""+data+" 00:00:00\", descricao=\""+jtfHistorico.getText()+"\",valor_bruto="+valor+" where cod_emp="+index.cod_emp+" and codigo="+jtfCodigo.getText());
            setConfirmaEditar(true);
            dispose();
        } catch (ParseException ex) {
            verErros.setErro(ex.getMessage());
        } catch (SQLException ex) {
            verErros.setErro(ex.getMessage());
        }

    }//GEN-LAST:event_jbSalvarActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbCancelar;
    private javax.swing.JButton jbCentroCusto;
    private javax.swing.JButton jbPessoa;
    private javax.swing.JButton jbPlanoContas;
    private javax.swing.JButton jbPlanoPag;
    private javax.swing.JButton jbSalvar;
    private javax.swing.JPanel jpMCEVPrincipal;
    private javax.swing.JTextField jtfCentroCusto;
    private javax.swing.JTextField jtfCodigo;
    private javax.swing.JFormattedTextField jtfDtVenc;
    private javax.swing.JTextPane jtfHistorico;
    private javax.swing.JTextField jtfPessoa;
    private javax.swing.JTextField jtfPlanoContas;
    private javax.swing.JTextField jtfPlanoPag;
    private javax.swing.JTextField jtfValor;
    // End of variables declaration//GEN-END:variables

}
